package com.sdut.material.controller;


import com.sdut.material.service.IManufactureService;
import com.sdut.material.util.JSONResult;
import com.sdut.material.util.LayUITableResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Yu
 * @since 2022-04-20
 */
@Controller
@RequestMapping("/manufacture")
public class ManufactureController {
    @Autowired
    private IManufactureService manufactureService;
    @RequestMapping("/getDemandCountPage")
    public String getDemandPage () {
        return "demand/demand_insert";
    }
    @RequestMapping("/getManufactureListPage")
    public String getManufactureListPage() {
        return "manufacture/manufacture_list";
    }
    @RequestMapping("/selectByPage")
    @ResponseBody
    public LayUITableResult selectByPage(Long page, Long limit) {
        return manufactureService.selectByPage(page,limit);
    }
    @RequestMapping("/getManufactureInsertPage")
    public String getManufactureInsertPage () {
        return "manufacture/manufacture_insert";
    }
    @RequestMapping("/insert")
    @ResponseBody
    public JSONResult insert(String productions,Integer count){
        JSONResult jsonResult = manufactureService.insert(productions,count);
        return jsonResult;
    }
    @RequestMapping("/cancelById")
    @ResponseBody
    public JSONResult cancelById(Integer manufactureId) {
        manufactureService.cancelById(manufactureId);
        return JSONResult.ok("取消成功");
    }
    @RequestMapping("/cancelAll")
    @ResponseBody
    public JSONResult cancelAll(String ids) {
        String[] idArray = ids.split(",");
        for (String id : idArray) {
            cancelById(Integer.parseInt(id));
        }
        return JSONResult.ok("取消成功");
    }
}

